package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo {
    /**
     * 用于演示集合的方法
     */
    public static void main(String[] args) {
        Collection collection = new ArrayList();
        collection.add(1);
        collection.add("one");
        collection.add("two");
        System.out.println(collection);

        //判断个数
        int count=collection.size();
        System.out.println(count);
        System.out.println(collection.isEmpty());//集合是空的吗 false
        collection.clear();//清空元素
        System.out.println(collection);
        Collection collection1 = new ArrayList();
        System.out.println(collection1.isEmpty());//true

        Collection collection2 = new ArrayList();
        collection2.add("one");
        collection2.add("two");
        collection2.add("three");
        System.out.println(collection2);
        System.out.println(collection2.contains("one"));

        collection2.remove("one");//移除
        System.out.println(collection2);
        System.out.println(collection2.remove("one"));//移除成功false

        Iterator iterator = collection2.iterator();
        iterator.next();
        iterator.next();
        while (iterator.hasNext()) {
            Object object = iterator.next();
            System.out.println(object);
        }

    }
}
